package br.com.jk.master;

import br.com.jk.cidade.CidadeJDialog;
import br.com.jk.cliente.ClienteJDialog;
import br.com.jk.config.Cfg;
import br.com.jk.config.CfgJDialog;
import br.com.jk.config.CfgPropUtil;
import br.com.jk.consultaxml.ProcessaXmlUtil;
import br.com.jk.cont.caixa.CaixaJDialog;
import br.com.jk.cont.planocontas.PlanoContasJDialog;
import br.com.jk.cotacao.CotacaoJDialog;
import br.com.jk.cotacao.itens.CotacaoItensJDialog;
import br.com.jk.cotacao.lancamento.CotacaoLancamentoJDialog;
import br.com.jk.empresa.EmpresaJDialog;
import br.com.jk.financeiro.banco.BancoJDialog;
import br.com.jk.financeiro.contaBanco.ContaBancoJDialog;
import br.com.jk.financeiro.movimento.MovimentoJDialog;
import br.com.jk.financeiro.movimentotipo.MovimentoTipoJDialog;
import br.com.jk.fornecedor.FornecedorJDialog;
import br.com.jk.master.processos.Processo;
import br.com.jk.master.processos.ProcessoTableCellRenderer;
import br.com.jk.master.processos.ProcessoTableModel;
import br.com.jk.produto.ProdutoJDialog;
import br.com.jk.usuario.Usuario;
import br.com.jk.usuario.UsuarioJDialog;
import br.com.jk.usuario.login.LoginJDialog;
import br.com.jk.usuario.permissoes.RegraRn;
import br.com.jk.util.StatusType.StatusProcesso;
import br.com.jk.util.Util;
import br.com.jk.valealim.cartao.CartaoJDialog;
import javax.swing.JInternalFrame;
import javax.swing.JOptionPane;
import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE;
import br.com.jk.valealim.cartaotipo.CartaoTipoJDialog;
import br.com.jk.valealim.cartaovenda.CartaoVendaJDialog;
import static java.awt.Frame.MAXIMIZED_BOTH;
import java.net.InetAddress;
import java.net.UnknownHostException;
import javax.swing.JLabel;
import javax.swing.JProgressBar;

/**
 * @author camilo
 */
public class Master extends javax.swing.JFrame {

  private static final long serialVersionUID = 1L;

  private final ProcessoTableModel processoTm = new ProcessoTableModel();
  public static Usuario usuarioLogado;

  /**
   * @version(0.1) Creates new form CadastroCliente
   */
  public Master() {
    initComponents();

    /*Toolkit theKit = this.getToolkit(); // for Fullscreen  
     this.setBounds(new Rectangle(theKit.getScreenSize()));
     jPanel1.setSize(this.getSize().width, 30);*/
    this.setMaximized();
    criaModel();
    jpbStatus.setVisible(false);

    jlUserDate.setText(Util.getDataAtual());
    jlBdIp.setText("Ip do banco de dados: " + getIpBd() + "  -  Ip local: " + getIpLocal());
    jlSistOp.setText("<html><b>  Sistema operacional:</b><i> " + System.getProperty("os.name")
            + " " + System.getProperty("os.version")
            + " " + System.getProperty("os.arch")+ "</i></html>  ");
    jlJava.setText("<html><b> Versão do JRE (Java)</b><i> - " + System.getProperty("java.version") + "</i></html>  ");
    
    jspMaster.setDividerLocation(0);
    System.out.println(this.getSize().getHeight() + " - " + this.getSize().getWidth());


    /*VersionProp ver = new VersionProp();
     Thread th = new Thread(ver);
     th.start();*/
    new Thread(new Runnable() {

      @Override
      public void run() {
        MasterSt.setJpbIndeterminate(true);
        MasterSt.setJlStatusMessage("Aguarde, o sistema está verificando a base de dados...");
        RegraRn regraRn = new RegraRn();
        regraRn.verificaNovaRegra();
        jbLogin.setEnabled(true);
        jlStatus.setText("Sistema iniciado");
        MasterSt.setJpbIndeterminate(false);
      }
    }).start();

    int x = desktopPane.getX();
    Double y = desktopPane.getSize().getWidth();
    jlBannerGrande.setLocation(x, y.intValue() - 41);
  }

  public void criaModel() {
    jtProcessos.setModel(processoTm);
    jtProcessos.getTableHeader().setReorderingAllowed(false);
    jtProcessos.getColumnModel().getColumn(ProcessoTableModel.COLUNA_COD_PROGRESS_BAR)
            .setCellRenderer(new ProcessoTableCellRenderer());

    Processo processo = new Processo();
    processo.setAndamento(new Integer[]{0, 20});
    processo.setDescricao("teste");
    processo.setMensagem("Testando jtProcesso");
    processo.setOrdem(1);
    processo.setStatus(StatusProcesso.EXECUTANDO);
    processoTm.adiciona(processo);

    Processo processo2 = new Processo();
    processo2.setAndamento(new Integer[]{0, 10});
    processo2.setDescricao("teste2");
    processo2.setMensagem("Testando jtProcesso");
    processo2.setOrdem(2);
    processo2.setStatus(StatusProcesso.EXECUTANDO);
    processoTm.adiciona(processo2);
  }

  public final void setMaximized() {
    this.setExtendedState(MAXIMIZED_BOTH);
    jspMaster.setDividerLocation(0);
  }

  /**
   * This method is called from within the constructor to initialize the form. WARNING: Do NOT
   * modify this code. The content of this method is always regenerated by the Form Editor.
   */
  @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jPanel1 = new javax.swing.JPanel();
    jlUserDate = new javax.swing.JLabel();
    jlStatus = new javax.swing.JLabel();
    jpbStatus = new javax.swing.JProgressBar();
    jlUser = new javax.swing.JLabel();
    jPanel2 = new javax.swing.JPanel();
    jlBdIp = new javax.swing.JLabel();
    jlSistOp = new javax.swing.JLabel();
    jlJava = new javax.swing.JLabel();
    jspMaster = new javax.swing.JSplitPane();
    desktopPane = new javax.swing.JDesktopPane();
    jbConsultaXml = new javax.swing.JButton();
    jbLogin = new javax.swing.JButton();
    jlBannerGrande = new javax.swing.JLabel();
    jspProcMens = new javax.swing.JSplitPane();
    jpProcessos = new javax.swing.JPanel();
    jScrollPane1 = new javax.swing.JScrollPane();
    jtProcessos = new javax.swing.JTable();
    jMenuBar1 = new javax.swing.JMenuBar();
    jmCadastro = new javax.swing.JMenu();
    jmiCliente = new javax.swing.JMenuItem();
    jmiFornecedor = new javax.swing.JMenuItem();
    jmiProduto = new javax.swing.JMenuItem();
    jSeparator1 = new javax.swing.JPopupMenu.Separator();
    jmFinanceiro = new javax.swing.JMenu();
    jmiBanco = new javax.swing.JMenuItem();
    jmiContaBanco = new javax.swing.JMenuItem();
    jmiTipoMovimentoBanco = new javax.swing.JMenuItem();
    jMenu1 = new javax.swing.JMenu();
    jmiPlanoContas = new javax.swing.JMenuItem();
    jmOutros = new javax.swing.JMenu();
    jmiCidade = new javax.swing.JMenuItem();
    jSeparator2 = new javax.swing.JPopupMenu.Separator();
    jmiUsuario = new javax.swing.JMenuItem();
    jmiEmpresa = new javax.swing.JMenuItem();
    jmMovimento = new javax.swing.JMenu();
    jmMovFinanceiro = new javax.swing.JMenu();
    jmiMovimentoBanco = new javax.swing.JMenuItem();
    jMenu2 = new javax.swing.JMenu();
    jmiCaixa = new javax.swing.JMenuItem();
    jmFerramentas = new javax.swing.JMenu();
    jmCotacao = new javax.swing.JMenu();
    jmiCotacoes = new javax.swing.JMenuItem();
    jmiCriaLista = new javax.swing.JMenuItem();
    jmiLancaProd = new javax.swing.JMenuItem();
    jmCotacaoCompra = new javax.swing.JMenu();
    jmiGeraXml = new javax.swing.JMenuItem();
    jmiImportaXml = new javax.swing.JMenuItem();
    jmiRecebimento = new javax.swing.JMenuItem();
    jmValeAlim = new javax.swing.JMenu();
    jmiCartoes = new javax.swing.JMenuItem();
    jmiTipoCartoes = new javax.swing.JMenuItem();
    jmiVendas = new javax.swing.JMenuItem();
    jmConfiguracoes = new javax.swing.JMenu();
    jmiConfiguracoes = new javax.swing.JMenuItem();
    jmAjuda = new javax.swing.JMenu();
    jmiSobre = new javax.swing.JMenuItem();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    setTitle("Aplicativos extras para Supermercado JK");
    setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
    setExtendedState(MAXIMIZED_BOTH);
    addComponentListener(new java.awt.event.ComponentAdapter() {
      public void componentMoved(java.awt.event.ComponentEvent evt) {
        formComponentMoved(evt);
      }
    });

    jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
    jPanel1.setLayout(new java.awt.BorderLayout());

    jlUserDate.setFont(new java.awt.Font("Liberation Sans", 1, 13)); // NOI18N
    jlUserDate.setText("99/99/9999");
    jlUserDate.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));
    jPanel1.add(jlUserDate, java.awt.BorderLayout.WEST);

    jlStatus.setFont(new java.awt.Font("Liberation Sans", 1, 13)); // NOI18N
    jlStatus.setText("Mensagem maior");
    jlStatus.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));
    jPanel1.add(jlStatus, java.awt.BorderLayout.PAGE_START);

    jpbStatus.setFont(new java.awt.Font("Liberation Sans", 0, 14)); // NOI18N
    jPanel1.add(jpbStatus, java.awt.BorderLayout.EAST);

    jlUser.setFont(new java.awt.Font("Liberation Sans", 1, 13)); // NOI18N
    jlUser.setText("Nenhum usuário logado");
    jlUser.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));
    jPanel1.add(jlUser, java.awt.BorderLayout.CENTER);

    java.awt.FlowLayout flowLayout1 = new java.awt.FlowLayout(java.awt.FlowLayout.LEFT, 0, 0);
    flowLayout1.setAlignOnBaseline(true);
    jPanel2.setLayout(flowLayout1);

    jlBdIp.setFont(new java.awt.Font("Liberation Sans", 1, 13)); // NOI18N
    jlBdIp.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/database_gear.png"))); // NOI18N
    jlBdIp.setText("BD - IP");
    jlBdIp.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));
    jPanel2.add(jlBdIp);

    jlSistOp.setFont(new java.awt.Font("Liberation Sans", 0, 13)); // NOI18N
    jlSistOp.setText("Sist.");
    jlSistOp.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));
    jPanel2.add(jlSistOp);

    jlJava.setFont(new java.awt.Font("Liberation Sans", 0, 13)); // NOI18N
    jlJava.setText("Java");
    jlJava.setBorder(null);
    jPanel2.add(jlJava);

    jPanel1.add(jPanel2, java.awt.BorderLayout.PAGE_END);

    getContentPane().add(jPanel1, java.awt.BorderLayout.SOUTH);

    jspMaster.setDividerLocation(0);
    jspMaster.setDividerSize(10);
    jspMaster.setOneTouchExpandable(true);

    desktopPane.setBorder(javax.swing.BorderFactory.createCompoundBorder());

    jbConsultaXml.setFont(new java.awt.Font("Liberation Sans", 1, 11)); // NOI18N
    jbConsultaXml.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/nfe-32.png"))); // NOI18N
    jbConsultaXml.setMnemonic('c');
    jbConsultaXml.setText("Consultar Arquivo XML NF-e");
    jbConsultaXml.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
    jbConsultaXml.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jbConsultaXmlActionPerformed(evt);
      }
    });
    desktopPane.add(jbConsultaXml);
    jbConsultaXml.setBounds(10, 10, 230, 40);

    jbLogin.setFont(new java.awt.Font("Liberation Sans", 1, 11)); // NOI18N
    jbLogin.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/meeting-participant-32.png"))); // NOI18N
    jbLogin.setMnemonic('u');
    jbLogin.setText("Efetuar Login");
    jbLogin.setEnabled(false);
    jbLogin.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
    jbLogin.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jbLoginActionPerformed(evt);
      }
    });
    desktopPane.add(jbLogin);
    jbLogin.setBounds(10, 60, 230, 40);

    jlBannerGrande.setIcon(new javax.swing.ImageIcon(getClass().getResource("/br/com/jk/imagens/PostgreSQL.Square_Banner.blue.300x250.png"))); // NOI18N
    desktopPane.add(jlBannerGrande);
    jlBannerGrande.setBounds(0, 260, 300, 250);

    jspMaster.setRightComponent(desktopPane);

    jspProcMens.setDividerLocation(0);
    jspProcMens.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
    jspProcMens.setOneTouchExpandable(true);

    jtProcessos.setFont(new java.awt.Font("Liberation Sans", 0, 12)); // NOI18N
    jtProcessos.setModel(new javax.swing.table.DefaultTableModel(
      new Object [][] {

      },
      new String [] {

      }
    ));
    jtProcessos.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
    jScrollPane1.setViewportView(jtProcessos);

    jpProcessos.add(jScrollPane1);

    jspProcMens.setBottomComponent(jpProcessos);

    jspMaster.setLeftComponent(jspProcMens);

    getContentPane().add(jspMaster, java.awt.BorderLayout.CENTER);

    jmCadastro.setText("Cadastros");

    jmiCliente.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F6, 0));
    jmiCliente.setText("Clientes");
    jmiCliente.setEnabled(false);
    jmiCliente.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jmiClienteActionPerformed(evt);
      }
    });
    jmCadastro.add(jmiCliente);

    jmiFornecedor.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F8, 0));
    jmiFornecedor.setText("Fornecedores");
    jmiFornecedor.setEnabled(false);
    jmiFornecedor.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jmiFornecedorActionPerformed(evt);
      }
    });
    jmCadastro.add(jmiFornecedor);

    jmiProduto.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F7, 0));
    jmiProduto.setText("Produtos");
    jmiProduto.setEnabled(false);
    jmiProduto.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jmiProdutoActionPerformed(evt);
      }
    });
    jmCadastro.add(jmiProduto);
    jmCadastro.add(jSeparator1);

    jmFinanceiro.setText("Financeiro");

    jmiBanco.setText("Bancos");
    jmiBanco.setEnabled(false);
    jmiBanco.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jmiBancoActionPerformed(evt);
      }
    });
    jmFinanceiro.add(jmiBanco);

    jmiContaBanco.setText("Conta Bancária");
    jmiContaBanco.setEnabled(false);
    jmiContaBanco.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jmiContaBancoActionPerformed(evt);
      }
    });
    jmFinanceiro.add(jmiContaBanco);

    jmiTipoMovimentoBanco.setText("Tipo Mov. Bancário");
    jmiTipoMovimentoBanco.setEnabled(false);
    jmiTipoMovimentoBanco.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jmiTipoMovimentoBancoActionPerformed(evt);
      }
    });
    jmFinanceiro.add(jmiTipoMovimentoBanco);

    jmCadastro.add(jmFinanceiro);

    jMenu1.setText("Contábil");

    jmiPlanoContas.setText("Plano de Contas");
    jmiPlanoContas.setEnabled(false);
    jmiPlanoContas.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jmiPlanoContasActionPerformed(evt);
      }
    });
    jMenu1.add(jmiPlanoContas);

    jmCadastro.add(jMenu1);

    jmOutros.setText("Outros");

    jmiCidade.setText("Cidades");
    jmiCidade.setEnabled(false);
    jmiCidade.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jmiCidadeActionPerformed(evt);
      }
    });
    jmOutros.add(jmiCidade);

    jmCadastro.add(jmOutros);
    jmCadastro.add(jSeparator2);

    jmiUsuario.setText("Usuários");
    jmiUsuario.setEnabled(false);
    jmiUsuario.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jmiUsuarioActionPerformed(evt);
      }
    });
    jmCadastro.add(jmiUsuario);

    jmiEmpresa.setText("Empresas");
    jmiEmpresa.setEnabled(false);
    jmiEmpresa.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jmiEmpresaActionPerformed(evt);
      }
    });
    jmCadastro.add(jmiEmpresa);

    jMenuBar1.add(jmCadastro);

    jmMovimento.setText("Movimentos");

    jmMovFinanceiro.setText("Financeiro");

    jmiMovimentoBanco.setText("Movimentação Bancária");
    jmiMovimentoBanco.setEnabled(false);
    jmiMovimentoBanco.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jmiMovimentoBancoActionPerformed(evt);
      }
    });
    jmMovFinanceiro.add(jmiMovimentoBanco);

    jmMovimento.add(jmMovFinanceiro);

    jMenu2.setText("Contábil");

    jmiCaixa.setText("Caixa Contábil");
    jmiCaixa.setEnabled(false);
    jmiCaixa.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jmiCaixaActionPerformed(evt);
      }
    });
    jMenu2.add(jmiCaixa);

    jmMovimento.add(jMenu2);

    jMenuBar1.add(jmMovimento);

    jmFerramentas.setMnemonic('f');
    jmFerramentas.setText("Ferramentas");

    jmCotacao.setText("Cotação");

    jmiCotacoes.setText("Cotações");
    jmiCotacoes.setEnabled(false);
    jmiCotacoes.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jmiCotacoesActionPerformed(evt);
      }
    });
    jmCotacao.add(jmiCotacoes);

    jmiCriaLista.setText("Criar Lista");
    jmiCriaLista.setEnabled(false);
    jmiCriaLista.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jmiCriaListaActionPerformed(evt);
      }
    });
    jmCotacao.add(jmiCriaLista);

    jmiLancaProd.setText("Lançar Produtos");
    jmiLancaProd.setEnabled(false);
    jmiLancaProd.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jmiLancaProdActionPerformed(evt);
      }
    });
    jmCotacao.add(jmiLancaProd);

    jmFerramentas.add(jmCotacao);

    jmCotacaoCompra.setText("Cotação Compra");

    jmiGeraXml.setText("Gerar XML (Lista)");
    jmCotacaoCompra.add(jmiGeraXml);

    jmiImportaXml.setText("Importar XML (Preços)");
    jmCotacaoCompra.add(jmiImportaXml);

    jmFerramentas.add(jmCotacaoCompra);

    jmiRecebimento.setMnemonic('r');
    jmiRecebimento.setText("Recebimentos");
    jmiRecebimento.setEnabled(false);
    jmiRecebimento.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jmiRecebimentoActionPerformed(evt);
      }
    });
    jmFerramentas.add(jmiRecebimento);

    jmValeAlim.setText("Vale Alimentação");

    jmiCartoes.setText("Cartões");
    jmiCartoes.setEnabled(false);
    jmiCartoes.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jmiCartoesActionPerformed(evt);
      }
    });
    jmValeAlim.add(jmiCartoes);

    jmiTipoCartoes.setText("Tipo Cartões");
    jmiTipoCartoes.setEnabled(false);
    jmiTipoCartoes.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jmiTipoCartoesActionPerformed(evt);
      }
    });
    jmValeAlim.add(jmiTipoCartoes);

    jmiVendas.setText("Vendas");
    jmiVendas.setEnabled(false);
    jmiVendas.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jmiVendasActionPerformed(evt);
      }
    });
    jmValeAlim.add(jmiVendas);

    jmFerramentas.add(jmValeAlim);

    jMenuBar1.add(jmFerramentas);

    jmConfiguracoes.setText("Configurações");

    jmiConfiguracoes.setText("Configurações Gerais");
    jmiConfiguracoes.setEnabled(false);
    jmiConfiguracoes.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        jmiConfiguracoesActionPerformed(evt);
      }
    });
    jmConfiguracoes.add(jmiConfiguracoes);

    jMenuBar1.add(jmConfiguracoes);

    jmAjuda.setText("Ajuda");

    jmiSobre.setText("Sobre");
    jmAjuda.add(jmiSobre);

    jMenuBar1.add(jmAjuda);

    setJMenuBar(jMenuBar1);

    pack();
  }// </editor-fold>//GEN-END:initComponents

  private void jmiRecebimentoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiRecebimentoActionPerformed

  }//GEN-LAST:event_jmiRecebimentoActionPerformed

  private void jmiTipoCartoesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiTipoCartoesActionPerformed
    CartaoTipoJDialog.getInstance(this, false).setVisible(true);
  }//GEN-LAST:event_jmiTipoCartoesActionPerformed

  private void jmiCartoesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiCartoesActionPerformed
    CartaoJDialog.getInstance(this, false).setVisible(true);
  }//GEN-LAST:event_jmiCartoesActionPerformed

  private void jmiVendasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiVendasActionPerformed
    CartaoVendaJDialog.getInstance(this, false).setVisible(true);
  }//GEN-LAST:event_jmiVendasActionPerformed

  private void jmiFornecedorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiFornecedorActionPerformed
    FornecedorJDialog.getInstance(this, false).setVisible(true);
  }//GEN-LAST:event_jmiFornecedorActionPerformed

  private void jmiCidadeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiCidadeActionPerformed
    CidadeJDialog.getInstance(this, false).setVisible(true);
  }//GEN-LAST:event_jmiCidadeActionPerformed

  private void jmiProdutoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiProdutoActionPerformed
    ProdutoJDialog.getInstance(this, false).setVisible(true);
  }//GEN-LAST:event_jmiProdutoActionPerformed

  private void jmiCriaListaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiCriaListaActionPerformed
    CotacaoItensJDialog.getInstance(this, false).setVisible(true);
  }//GEN-LAST:event_jmiCriaListaActionPerformed

  private void jbConsultaXmlActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbConsultaXmlActionPerformed
    ProcessaXmlUtil.main();
  }//GEN-LAST:event_jbConsultaXmlActionPerformed

  private void jmiCotacoesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiCotacoesActionPerformed
    CotacaoJDialog.getInstance(this, false).setVisible(true);
  }//GEN-LAST:event_jmiCotacoesActionPerformed

  private void formComponentMoved(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentMoved
    this.setMaximized();
  }//GEN-LAST:event_formComponentMoved

  private void jmiClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiClienteActionPerformed
    ClienteJDialog.getInstance(this, false).setVisible(true);
  }//GEN-LAST:event_jmiClienteActionPerformed

  private void jmiLancaProdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiLancaProdActionPerformed
    CotacaoLancamentoJDialog.getInstance(this, false).setVisible(true);
  }//GEN-LAST:event_jmiLancaProdActionPerformed

  private void jmiUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiUsuarioActionPerformed
    UsuarioJDialog.getInstance(this, false).setVisible(true);
  }//GEN-LAST:event_jmiUsuarioActionPerformed

  private void jmiBancoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiBancoActionPerformed
    BancoJDialog.getInstance(this, false).setVisible(true);
  }//GEN-LAST:event_jmiBancoActionPerformed

  private void jmiContaBancoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiContaBancoActionPerformed
    ContaBancoJDialog.getInstance(this, false).setVisible(true);
  }//GEN-LAST:event_jmiContaBancoActionPerformed

  private void jmiTipoMovimentoBancoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiTipoMovimentoBancoActionPerformed
    MovimentoTipoJDialog.getInstance(this, false).setVisible(true);
  }//GEN-LAST:event_jmiTipoMovimentoBancoActionPerformed

  private void jmiMovimentoBancoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiMovimentoBancoActionPerformed
    MovimentoJDialog.getInstance(this, false).setVisible(true);
  }//GEN-LAST:event_jmiMovimentoBancoActionPerformed

  private void jbLoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbLoginActionPerformed
    new LoginJDialog(this, true).setVisible(true);
  }//GEN-LAST:event_jbLoginActionPerformed

  private void jmiEmpresaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiEmpresaActionPerformed
    EmpresaJDialog.getInstance(this, false).setVisible(true);
  }//GEN-LAST:event_jmiEmpresaActionPerformed

  private void jmiConfiguracoesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiConfiguracoesActionPerformed
    CfgJDialog.getInstance(this, true).setVisible(true);
  }//GEN-LAST:event_jmiConfiguracoesActionPerformed

  private void jmiPlanoContasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiPlanoContasActionPerformed
    PlanoContasJDialog.getInstance(this, false).setVisible(true);
  }//GEN-LAST:event_jmiPlanoContasActionPerformed

  private void jmiCaixaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmiCaixaActionPerformed
    CaixaJDialog.getInstance(this, false).setVisible(true);
  }//GEN-LAST:event_jmiCaixaActionPerformed

  /**
   * @param args the command line arguments
   */
  public static void main(String args[]) {
    /*
     * Set the Nimbus look and feel
     */
    //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
     * If Nimbus (introduced in Java SE 6) is not available, stay with the
     * default look and feel. For details see
     * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
     */
    try {
      for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
        if ("Nimbus".equals(info.getName())) {
          javax.swing.UIManager.setLookAndFeel(info.getClassName());
          break;
        }
      }
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
      java.util.logging.Logger.getLogger(Master.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>

    /*
     * Create and display the form
     */
    java.awt.EventQueue.invokeLater(new Runnable() {
      @Override
      public void run() {
        new Master().setVisible(true);
      }
    });
  }
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JDesktopPane desktopPane;
  private javax.swing.JMenu jMenu1;
  private javax.swing.JMenu jMenu2;
  private javax.swing.JMenuBar jMenuBar1;
  private javax.swing.JPanel jPanel1;
  private javax.swing.JPanel jPanel2;
  private javax.swing.JScrollPane jScrollPane1;
  private javax.swing.JPopupMenu.Separator jSeparator1;
  private javax.swing.JPopupMenu.Separator jSeparator2;
  private javax.swing.JButton jbConsultaXml;
  private javax.swing.JButton jbLogin;
  private javax.swing.JLabel jlBannerGrande;
  public static javax.swing.JLabel jlBdIp;
  public static javax.swing.JLabel jlJava;
  public static javax.swing.JLabel jlSistOp;
  public static javax.swing.JLabel jlStatus;
  public static javax.swing.JLabel jlUser;
  public static javax.swing.JLabel jlUserDate;
  private javax.swing.JMenu jmAjuda;
  public static javax.swing.JMenu jmCadastro;
  private javax.swing.JMenu jmConfiguracoes;
  private javax.swing.JMenu jmCotacao;
  private javax.swing.JMenu jmCotacaoCompra;
  private javax.swing.JMenu jmFerramentas;
  private javax.swing.JMenu jmFinanceiro;
  private javax.swing.JMenu jmMovFinanceiro;
  private javax.swing.JMenu jmMovimento;
  public static javax.swing.JMenu jmOutros;
  private javax.swing.JMenu jmValeAlim;
  public static javax.swing.JMenuItem jmiBanco;
  public static javax.swing.JMenuItem jmiCaixa;
  public static javax.swing.JMenuItem jmiCartoes;
  public static javax.swing.JMenuItem jmiCidade;
  public static javax.swing.JMenuItem jmiCliente;
  public static javax.swing.JMenuItem jmiConfiguracoes;
  public static javax.swing.JMenuItem jmiContaBanco;
  public static javax.swing.JMenuItem jmiCotacoes;
  public static javax.swing.JMenuItem jmiCriaLista;
  public static javax.swing.JMenuItem jmiEmpresa;
  public static javax.swing.JMenuItem jmiFornecedor;
  public static javax.swing.JMenuItem jmiGeraXml;
  public static javax.swing.JMenuItem jmiImportaXml;
  public static javax.swing.JMenuItem jmiLancaProd;
  public static javax.swing.JMenuItem jmiMovimentoBanco;
  public static javax.swing.JMenuItem jmiPlanoContas;
  public static javax.swing.JMenuItem jmiProduto;
  private javax.swing.JMenuItem jmiRecebimento;
  private javax.swing.JMenuItem jmiSobre;
  public static javax.swing.JMenuItem jmiTipoCartoes;
  public static javax.swing.JMenuItem jmiTipoMovimentoBanco;
  public static javax.swing.JMenuItem jmiUsuario;
  public static javax.swing.JMenuItem jmiVendas;
  private javax.swing.JPanel jpProcessos;
  public static javax.swing.JProgressBar jpbStatus;
  private javax.swing.JSplitPane jspMaster;
  private javax.swing.JSplitPane jspProcMens;
  private javax.swing.JTable jtProcessos;
  // End of variables declaration//GEN-END:variables

  /**
   * private void CriaJanela() { if (jifCadastroClientes == null) { jifCadastroClientes = new
   * JifCadastroClientes(); desktopPane.add(jifCadastroClientes); }
   *
   * jifCadastroClientes.setVisible(true);
   *
   * }
   */
  private void abrirJIFrame(JInternalFrame jIntFrame) {
    jIntFrame.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    desktopPane.add(jIntFrame);
    jIntFrame.setVisible(true);
  }

  private void adiciona() {
    Integer[] valorAtual = (Integer[]) processoTm.getValueAt(jtProcessos.getSelectedRow(), ProcessoTableModel.COLUNA_COD_PROGRESS_BAR);
    valorAtual[0]++;
    processoTm.setValueAt(valorAtual, jtProcessos.getSelectedRow(), ProcessoTableModel.COLUNA_COD_PROGRESS_BAR);
  }

  private String getIpBd() {
    CfgPropUtil cfgP = new CfgPropUtil();
    Cfg prop = cfgP.getCfgProp();
    return prop.getIp();
  }

  private String getIpLocal() {
    String ip = null;
    try {
      InetAddress inet = InetAddress.getLocalHost();
      ip = inet.getHostAddress();
    } catch (UnknownHostException e) {
      Util.msgErro(e, "Erro ao obter o endereço IP local.");
    }
    return ip;
  }

  public class ThreadJIFrame extends Thread {

    private final JInternalFrame jIntFrame;

    public ThreadJIFrame(JInternalFrame jIntFrame) {
      this.jIntFrame = jIntFrame;
    }

    @Override
    public void run() {
      try {
        abrirJIFrame(jIntFrame);
      } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, ex.getMessage());
      }
    }
  }

  protected static JLabel getJlStatus() {
    return jlStatus;
  }

  protected static void setJlStatus(JLabel jlStatus) {
    Master.jlStatus = jlStatus;
  }

  protected static JLabel getJlUserDate() {
    return jlUserDate;
  }

  protected static void setJlUserDate(JLabel jlUserDate) {
    Master.jlUserDate = jlUserDate;
  }

  protected static JProgressBar getJpbStatus() {
    return jpbStatus;
  }

  protected static void setJpbStatus(JProgressBar jpbStatus) {
    Master.jpbStatus = jpbStatus;
  }
}
